#include <iostream>
#include <fstream>
#include <sstream>
#include "..\src\AsmIndent.cpp"
using namespace std;

int asm_formatter( char* argv, char* argv2 )
{
    ifstream asm_file(argv);
    if (!asm_file.is_open())
    {
       cout << "Open Fail!" << endl;
       return 1;
    }
    if (asm_file.good())
    {
        ostringstream oss;
        oss << asm_file.rdbuf();
        string strText = oss.str();
        string strOut;

        CAsmIndent asmformatter;
        asmformatter.AsmTidyMain(strText.c_str(), strOut);

        ofstream result_file(argv2, ios::binary);
        if (!result_file.is_open())
        {
             cout << "Open result_file Fail!" << endl;
             return 1;
        }
        result_file << strOut;
        result_file.close();
    }
    asm_file.close();
    cout << "8051 assembly formatter is completed." << endl;
    return 0;
}

int main( int argc, char* argv[] )
{
    if (argc == 1)
    {
        cout << "This is 8051 assembly formatter." << endl;
    }
    else
    {
        asm_formatter( argv[1], argv[2] );
    }
    return 0;
}
